#include<iostream>
#include <string.h>
#include <graphics.h>		// ����ͼ�ο�ͷ�ļ�
#include <conio.h>
#include"pointlist.h"
using namespace std;
void makeSquare(){
	PointList square;
	square.append(Point(100,100));
	square.append(Point(100,200));
	square.append(Point(200,200));
	square.append(Point(200,100));
	Point vertex0,vertex1,vertex2;
	square.gotoBeginning();
	initgraph(640, 480);	// ������ͼ���ڣ���СΪ 640x480 ����
	bool first=true;
	do{
		if(first)
		{
			vertex2=square.getCursor();
			vertex0.x=vertex2.x;
			vertex0.y=vertex2.y;
			first=false;
		}
		else{
			vertex1.x=vertex2.x;
			vertex1.y=vertex2.y;
			vertex2=square.getCursor();
			line(vertex1.x,vertex1.y,vertex2.x,vertex2.y);
		}
		//putpixel(vertex.x,vertex.y,WHITE);
	}while(square.gotoNext());
	line(vertex2.x,vertex2.y,vertex0.x,vertex0.y);
	getch();				// �����������
	closegraph();
}
makeDragon(){
	PointList dragon;
	dragon.append(Point(100,100));
	dragon.append(Point(100,200));
	dragon.append(Point(200,200));
	dragon.append(Point(200,100));
	dragon.append(Point(300,100));
	Point vertex0,vertex1,vertex2;
	dragon.gotoBeginning();
	initgraph(640, 480);	// ������ͼ���ڣ���СΪ 640x480 ����
	bool first=true;
	do{
		if(first)
		{
			vertex2=square.getCursor();
			vertex0.x=vertex2.x;
			vertex0.y=vertex2.y;
			first=false;
		}
		else{
			vertex1.x=vertex2.x;
			vertex1.y=vertex2.y;
			vertex2=square.getCursor();
			line(vertex1.x,vertex1.y,vertex2.x,vertex2.y);
		}
		//putpixel(vertex.x,vertex.y,WHITE);
	}while(square.gotoNext());
	line(vertex2.x,vertex2.y,vertex0.x,vertex0.y);
	getch();				// �����������
	closegraph();
}
void main(){
	PointList polygon;
	Point vertex;
	polygon.append(Point(100,200));
	polygon.append(Point(129,271));
	polygon.append(Point(200,300));
	polygon.append(Point(271,271));
	polygon.append(Point(300,200));
	polygon.append(Point(271,129));
	polygon.append(Point(200,100));
	polygon.append(Point(129,129));
	polygon.append(Point(100,200));
	char c[10];
	int x,y;
	char *token;
	char sep[]=" ";
	while(true){
		cin.getline(c,10);
		//cout<<c<<endl;
		switch(c[0]){
		case '+':
		{
			token=strtok(c,sep);
			token=strtok(NULL,sep);
			x=std::atoi(token);
			cout<<x;
			token=strtok(NULL,sep);
			y=std::atoi(token);
			cout<<","<<y<<endl;
			polygon.append(Point(float(x),float(y)));
			continue;
		}
		case'@':
		{
			polygon.getCursor();
			//cout<<"("<<p.x<<p.y<<")"<<endl;
			continue;
		}
		case 'N':
			if(polygon.gotoNext())
				cout<<"����ƶ��ɹ���"<<endl;
			else
				cout<<"����ƶ�ʧ�ܡ�"<<endl;
			continue;
		case 'P':
			if(polygon.gotoPrior())
				cout<<"��ǰ�ƶ��ɹ���"<<endl;
			else
				cout<<"��ǰ�ƶ�ʧ�ܡ�"<<endl;
			continue;
		case '<':
			polygon.gotoBeginning();
			continue;
		case '>':
			polygon.gotoEnd();
			continue;
		case 'E':
			if(polygon.isEmpty())
				cout<<"The List is Empty."<<endl;
			else
				cout<<"The list is not empty."<<endl;
			continue;
		case'F':
			if(polygon.isFull())
				cout<<"The list is full."<<endl;
			else
				cout<<"The list is not full."<<endl;
			continue;
		case 'C':
			polygon.clear();
			continue;
		case 'Q':
			goto exit0;
			//break;
		case 'D':
			if(polygon.isEmpty())
				break;
			else
				makeSquare();
			break;
		}
	}
exit0:
	;//getchar();
}